﻿@model WeProjectsModel.News
<style type="text/css">
    section.container form > div {
        margin-top: 10px;
        margin-bottom: 10px;
    }
</style>

@{
    List<WeProjectsModel.Tag> tags = ViewBag.Tags;
    List<WeProjectsModel.Tag> ctags = ViewBag.cTags;
}
@{
    ViewBag.Title = "Edit";
    int usrId=int.Parse(Membership.GetUser().ProviderUserKey.ToString());
    if(Model.Project.OwnerID!= usrId && Model.MemberID!=usrId && !Roles.IsUserInRole("sysadmin"))
    {
        Response.Write("您没有权限操作!");
        Response.End();
    }
}
@Html.Partial("../project/_projectMenu2")
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>

<h2>@Model.Project.Title > 编辑新闻</h2>

@using (Html.BeginForm(FormMethod.Post)) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    <div>
        @Html.EditorFor(model => model.Title)
        @Html.ValidationMessageFor(model => model.Title)
    </div>
    <div class="marginL-20p">
        @foreach (var c in tags)
        {
            <label class="checkbox">
                <input type="checkbox" name="tags" value="@c.Code"> @c.Name
            </label>
        }
    </div>
    <div>
        <script id="editor" name="NewsContent" type="text/plain" style="width:100%;height:300px;">
        </script>
        @Html.ValidationMessageFor(model => model.NewsContent)
    </div>
    <input type="hidden" name="NewsContent" id="NewsContent" />
    <input type="hidden" name="ProjectID" value="@Model.ProjectID" />  
    @*<table class="table">
    <tr><td style="background-color: #dedede; width: 10%;">标题</td>
<td><input type="hidden" name="ID" value="@Html.ViewContext.RouteData.Values["id"]" />
        <input type="hidden" name="ProjectID" value="@Model.ProjectID" />        
        @Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)</td>
</tr>

        <tr><td>标签</td>
        <td>           
                    @foreach(var ct in ctags)
                            {
                        <label class="checkbox">
                        <input type="checkbox" name="tags" value="@ct.Code" checked="checked">@ct.Name
                    </label>
                    }

        </td>
        </tr>
    <tr><td style="background-color: #dedede; width: 10%;">正文</td>
<td><input type="hidden" name="NewsContent" id="NewsContent" />
<script id="editor" type="text/plain" style="width:100%;height:300px;"></script>
@Html.ValidationMessageFor(model => model.NewsContent)</td></tr>
</table>*@
     <div class="text-center">
         <input type="submit" value="提交" class="btn btn-success" />
    </div>
}
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script type="text/javascript">
    var ue = UE.getEditor('editor');
    ue.ready(function () {
        var content = '@Html.Raw(Model.NewsContent)';
        ue.setContent(content);
    });
    $('form').submit(function () {
        $('#NewsContent').val(ue.getContent());
        alert($('#NewsContent').content);
    });
</script>

@*<div>
    @Html.ActionLink("返回列表", "News", "Project", new { id = Model.ProjectID }, new { })
</div>*@

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
